<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>天气查询</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
    </script>
</head>
<body>
    <div id="app">
        <p>城市:{{cityname}}</p>
        <p>温度:{{temp}}℃</p>
        <p>风向:{{WD}}</p>
        <p>风级:{{WS}}</p>
        <p>风速:{{wse}}</p>
        <p>相对湿度:{{SD}}</p>
        <p>天气:{{weather}}</p>
        <p>PM2.5:{{pm25}}</p>
        <p>天气数据最后更新时间:{{time}}</p>
        <p>降雨预测返回信息:{{forecast}}</p>
        <button @click="change">点击一下</button>
    </div>
    <script src="./vue.js"></script>
    <script>
        let app=new Vue({
            el:"#app",
            data:{
                cityname:"",
                temp:"",
                WD:"",
                WS:"",
                wse:"",
                SD:"",
                weather:"",
                pm25:"",
                time:"",
                forecast:"",
            },
            mounted() {
                this.change()
            },
            methods: {
                change() {
                    $.ajax({
                        type: "GET",
                        url: "https://api.muxiaoguo.cn/api/tianqi",
                        data: {
                            api_key: "9d2b3dddd201b484",
                            city:"成都",
                            type:1,//1=当天,2=未来7天,3=未来8-15天,4.降雨预测
                        },
                        dataType: "json"
                    }).then(res => {
                        console.log(res);
                        this.cityname=res.data.cityname;
                        this.temp=res.data.temp;
                        this.WD=res.data.WD;
                        this.WS=res.data.WS;
                        this.wse=res.data.wse;
                        this.SD=res.data.SD;
                        this.weather=res.data.weather;
                        this.pm25=res.data.pm25;
                        this.time=res.data.time;
                        this.forecast=res.data.forecast;
                    })
                }
            }
        })
    </script>
</body>
</html>